﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jxym.wlkc2011.WebSite;
using Jxym.DBUtility;
using Jxym.wlkc2011.Module.CMS.MODEL;

namespace Jxym.wlkc2011
{
    public partial class xx : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.Params["siteName"] != null)
                {
                    _siteName = Request.Params["siteName"];

                    if (Request.Params["m"] != null)
                    {
                        _m = Request.Params["m"];
                    }

                    if (_siteName == "") { return; }

                    GetSiteTitle(_siteName);

                    GetKcms(_siteName);

                    Jxym.wlkc2011.MyGet.GetIDByName(zjgx1, "主讲人");

                    Repeater1.DataSource = GetKcxx(_siteName, "课程学习");
                    Repeater1.DataBind();
                }
            }
        }

        private static IList<Cms_ContentClass> GetKcxx(string _siteName, string title)
        {
            MsSqlDal<Cms_Site_ContentClass> cscc = new MsSqlDal<Cms_Site_ContentClass>();

            MsSqlDal<Cms_ContentClass> ccc = new MsSqlDal<Cms_ContentClass>();

            IList<Cms_Site_ContentClass> csccList = cscc.GetList("SiteName='" + _siteName + "'", null, "", 0);

            IList<Cms_ContentClass> cccList = new List<Cms_ContentClass>();

            foreach (Cms_Site_ContentClass csccInfo in csccList)
            {
                Cms_ContentClass cccInfo = ccc.GetModel(csccInfo.ContentClassID);

                if (cccInfo != null)
                {
                    if (cccInfo.Title.Contains(title))
                    {
                        cccList = ccc.GetList("ParentID=" + cccInfo.ID, null, "", 0);
                        xxCount = cccList.Count;
                        break;
                    }
                }
            }
            return cccList;
        }

        private static void GetKcms(string _siteName)
        {
            MsSqlDal<Cms_Site_ContentClass> cscc = new MsSqlDal<Cms_Site_ContentClass>();

            MsSqlDal<Cms_ContentClass> ccc = new MsSqlDal<Cms_ContentClass>();

            IList<Cms_Site_ContentClass> csccList = cscc.GetList("", null, "", 0);

            IList<Cms_ContentClass> cccList = new List<Cms_ContentClass>();

            foreach (Cms_Site_ContentClass csccInfo in csccList)
            {
                Cms_ContentClass cccInfo = ccc.GetModel(csccInfo.ContentClassID);

                if (cccInfo != null)
                {
                    if (cccInfo.Title.Contains("课程描述"))
                    {
                        _mid = cccInfo.ID;

                        MsSqlDal<Cms_Content> cc = new MsSqlDal<Cms_Content>();

                        Cms_Content ccInfo = cc.GetModel("ContentClassID=" + cccInfo.ID, null);

                        if (ccInfo != null)
                        {
                            KCMS = Jxym.Tools.Char.MySubstring(Jxym.Tools.Char.DelHTML(ccInfo.Html), 120);
                            KCMSID = ccInfo.ID;
                        }

                        break;
                    }
                }
            }
        }

        private static void GetSiteTitle(string _siteName)
        {
            MsSqlDal<Cms_Site> cs = new MsSqlDal<Cms_Site>();

            Cms_Site csInfo = cs.GetModel("Name='" + _siteName + "'", null);

            if (csInfo != null)
            {
                SiteTitle = csInfo.Title;
            }
        }

        public int index = 0;
        public static string SiteTitle = "";
        public static string _siteName = "";
        public static string KCMS = "暂无信息";
        public static int KCMSID = 0;

        public static int xxCount { get; set; }

        public string _m { get; set; }

        public static int _mid { get; set; }
    }
}